package com.shxzz.easy12306.services.ticket.service.impl;

import com.shxzz.easy12306.framework.starter.cache.StringRedisTemplateProxy;
import com.shxzz.easy12306.services.ticket.common.constant.RedisKeyConstant;
import com.shxzz.easy12306.services.ticket.common.constant.TicketConstant;
import com.shxzz.easy12306.services.ticket.dao.entity.TrainDO;
import com.shxzz.easy12306.services.ticket.dao.mapper.TrainMapper;
import com.shxzz.easy12306.services.ticket.service.TrainService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 列车信息服务层接口实现
 * @author shxzz
 * @create 2024-03-11-14:57
 */
@RequiredArgsConstructor
@Service
public class TrainServiceImpl implements TrainService {

    private final StringRedisTemplateProxy stringRedisTemplateProxy;
    private final TrainMapper trainMapper;

    @Override
    public TrainDO getTrainInfo(String trainId) {
        return stringRedisTemplateProxy.safeGet(
                RedisKeyConstant.TRAIN_INFO_PREFIX + trainId,
                TrainDO.class,
                () -> trainMapper.selectById(trainId),
                TicketConstant.ADVANCED_QUERY_TICKET_DAY,
                TimeUnit.DAYS
        );
    }

}
